package com.yalemang.photovalut.ui.choice.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.yalemang.framework.base.BaseVBAdapter
import com.yalemang.photovalut.base.BaseChickAdapter
import com.yalemang.photovalut.base.ext.load
import com.yalemang.photovalut.base.helper.CommonDrawableHelper
import com.yalemang.photovalut.databinding.ItemChoiceFileBinding

class ChoicePhotoAdapter(
    private var photoList: ArrayList<String>
) : BaseVBAdapter<String, ItemChoiceFileBinding>(photoList) {

    private var photoPaths = HashSet<String>()

    fun getPhotoPathSet(): HashSet<String>{
        return photoPaths
    }

    override fun onBindViewHolder(
        holder: CommonViewHolder<ItemChoiceFileBinding>,
        data: String,
        position: Int
    ) {
        holder.binding.ivChoice.background = CommonDrawableHelper.Builder().setTop(8f).builder()
        holder.binding.ivChoice.setOnClickListener{
            if (itemClickListener != null) {
                itemClickListener.invoke(data, position)
            }
        }
        holder.binding.ivChoice.load(photoList[position])

        holder.binding.cbChoice.setOnClickListener{
            if (photoPaths.contains(photoList[position])){
                photoPaths.remove(photoList[position])
                holder.binding.cbChoice.isChecked = false
            }else{
                photoPaths.add(photoList[position])
                holder.binding.cbChoice.isChecked = true
            }
        }
    }
}